<template>
  <div class="hot-recommendation">
    <div class="hot-title">
      <h3>热门任务推荐</h3>
      <span>市场热门需求，抢占商业先机</span>
    </div>
    <div class="hot-box">
      <template v-for="(item, index) in hotTasks" :key="index">
        <div class="hot">
          <div class="hot-head">
            <span class="hot-head-left">{{ item.title }}</span>
            <span class="hot-head-right" @click="doReFresh(index)">
              <p>换一批</p>
              <img
                :class="['img', index == refreshIndex ? 'active' : '']"
                src="@/assets/img/ic_Refresh.png"
                alt="换一批"
              />
            </span>
          </div>
          <div class="hot-content">
            <div class="hot-content-item">
              <span class="one">任务名</span>
              <span>项目积分</span>
              <span>投标人数</span>
            </div>
            <template v-for="(iten, ind) in item.content" :key="ind">
              <div class="hot-content-item hover">
                <span class="one">{{ iten?.projectName }}</span>
                <span class="two">{{ iten?.projectScore }}</span>
                <span class="three">{{ iten?.bidderCount }}</span>
              </div>
            </template>
          </div>
        </div>
      </template>
    </div>
  </div>
</template>

<script lang="ts" setup>
import _ from 'lodash'
import { ref ,defineProps} from 'vue'

//传递数据
const prop = defineProps(['hotTasks'])
const emit = defineEmits(['refresh'])


// 更换一批的动画
const refreshIndex = ref<number>(-1)
const refresh = (index: number):void => {
  refreshIndex.value = index
  prop.hotTasks[index].nowPage++
  if (prop.hotTasks[index].nowPage >= prop.hotTasks[index].allPagesNumber) {
    prop.hotTasks[index].nowPage = 0
  }
  const data = { limit: 6, nowPage: prop.hotTasks[index].nowPage, projectType: prop.hotTasks[index].projectType }
  emit('refresh',data,index)
  setTimeout(() => {
    refreshIndex.value = -1
  }, 500)
}
// 防抖函数
const doReFresh = _.debounce(refresh, 1000, { leading: true, maxWait: 1000 })
</script>

<style lang="less" scoped>
@keyframes myrotete {
  from {
    transform: rotate(0);
  }
  to {
    transform: rotate(360deg);
  }
}
.hot-recommendation {
  display: flex;
  margin: 0 auto;
  padding-bottom: 50px;
  background-color: #fff;
  flex-direction: column;
  justify-content: center;
  .hot-title {
    margin: 20px auto;
    margin-top: 0;
    h3 {
      text-align: center;
      font-size: 24px;
      font-weight: 500;
      color: #0b121a;
      line-height: 33px;
    }
    span {
      text-align: center;
      font-size: 14px;
      font-weight: 400;
      color: #828c99;
      line-height: 30px;
    }
  }

  .hot-box {
    margin: 0 auto;
    padding: 0 60px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    .hot {
      flex: 25%;
      display: flex;
      margin: 20px 25px;
      padding: 30px 30px 10px 30px;
      border: 1 solid #6a6e77;
      background: #fff;
      border-radius: 16px;
      border: 1px solid rgba(0, 0, 0, 0.05);
      box-shadow: 0px 4px 60px rgb(167 167 167 / 10%);
      flex-direction: column;
      .hot-head {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 10px;
        .hot-head-left {
          font-size: 20px;
          font-weight: 700;
        }
        .hot-head-right {
          display: flex;
          font-size: 14px;
          cursor: pointer;
          img {
            margin-left: 18px;
            width: 16px;
            height: 16px;
            margin-right: 4px;
          }
          .active {
            animation-name: myrotete;
            animation-duration: 0.5s;
            animation-iteration-count:1;
          }
        }
      }
      .hot-content {
        .hot-content-item {
          padding: 10px 5px;
          font-size: 13px;
          display: flex;
          border-radius: 4px;
          justify-content: space-between;
          .one {
            width: 140px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
          .two {
            padding-right: 20px;
          }
          .three {
            padding-right: 20px;
          }
        }
        .hover:hover {
          background-color: #f0f2f5;
          cursor: pointer;
        }
      }
      .hot-footer {
        align-self: last baseline;
        margin-top: 10px;
        cursor: pointer;
        img {
          padding-top: 4px;
          padding-right: 20px;
          height: 9px;
          width: 16px;
        }
      }
    }
  }
}
</style>
